<script>
	import config from './config'
	import store from '@/store'
	import {
		getToken
	} from '@/utils/auth'

	export default {
		onLaunch: function() {
			this.initApp()
			//  进入页面的时候执行一次
			uni.getSystemInfo({
				success: function(res) {
					const windowWidth = res.windowWidth; // 窗口宽度
					// const windowHeight = res.windowHeight; // 窗口高度
					console.log(windowWidth);
					// console.log(windowHeight);
					if (windowWidth > 768) {
						uni.hideTabBar()
						document.getElementsByClassName('uni-page-head')[0].style.display = 'none'
					} else {
						uni.showTabBar()
						document.getElementsByClassName('uni-page-head')[0].style.display = 'block'
					}
				}
			});

		},
		onShow() {
			//进入页面不触发获取数据  改变的时候触发
			const windowResizeCallback = (res) => {
				// console.log('变化后的窗口宽度=' + res.size.windowWidth)
				if (res.size.windowWidth > 768) {
					uni.hideTabBar()
					document.getElementsByClassName('uni-page-head')[0].style.display = 'none'
				} else {
					uni.showTabBar()
					document.getElementsByClassName('uni-page-head')[0].style.display = 'block'
				}
				// console.log('变化后的窗口高度=' + res.size.windowHeight)
			}
			uni.onWindowResize(windowResizeCallback)
		},
		methods: {
			// 初始化应用
			initApp() {
				// 初始化应用配置
				this.initConfig()
				// 检查用户登录状态
				//#ifdef H5
				//this.checkLogin()
				//#endif
			},
			initConfig() {
				this.globalData.config = config
			},
			checkLogin() {
				if (!getToken()) {
					this.$tab.reLaunch('/pages/login')
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/scss/index.scss'
</style>
<style>
	@media screen and (min-width: 320px) {
		.uni-app--showtopwindow uni-page-head {
			display: block;
		}

	}

	@media screen and (min-width: 768px) {

		.uni-app--showtopwindow uni-page-head {
			display: none;
		}
	}
</style>